package original;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;

public class OriginalJava extends JFrame
{
	public int rectX = 50;
	public int rectY = 0;
	int inputHeightVoltage = 0;
	int inputHeightTemperature = 0;
	char star = '$';
	public String inputVoltage;
	public String inputTemperature;
	
    public OriginalJava()
    {
        super("Using Colors");
        setSize(1000, 600);
        show();
    }
   
    public void paint(Graphics g)
    {
    	//Draw axis for Temperature vs Battery graph
    	g.fillRect(40, 300, 1, 150);//Vertical line
    	//g.drawLine(40, 450, 400, 450);//Horizontal line
    	g.drawString("T", 10, 400);//T label y-axis
    	g.drawString("Battery Number", 70, 490);//Battery Number x - axis label
    	g.drawString("'Temperature vs Battery Number Graph'", 50, 300);    	
    	
    	//Draw axis for V vs Battery Number graph
    	g.drawString("V", 10, 150);//Y Label string
    	g.drawString("Battery No.", 100, 250);//X label string
    	g.drawString("'Voltage Versus Battery Number Graph'", 80, 40);
    	     
    	g.setColor(Color.BLACK);
        g.drawLine(40, 50, 40, 200);//Vertical line
        //g.drawLine(40, 200, 800, 200);//Horizontal line
        
        try
        {
        	Scanner inFile   = new Scanner(new FileReader("/home/mhhubhe/Downloads/bvx/sampleInput.txt"));
        	//Scanner inFile   = new Scanner(new FileReader("D:\\sampleInput.txt"));
        	int counter = 0;
        	int batteryCounter = 1;
        	//int voltageCounter = 1;
        	do
        		{
        			//Read Voltage values from file
        		    inputVoltage = inFile.next();
        			inputHeightVoltage  = Integer.parseInt(inputVoltage);
        			
        			//Read Temperature values from file
        			inputTemperature = inFile.next();
        			inputHeightTemperature = Integer.parseInt(inputTemperature);
        			
        			g.setColor(Color.BLUE);//Set color for bars
        			
        			//Draw bars for Temperature
        			g.fillRect(40 + counter, 450 - inputHeightTemperature, 10, inputHeightTemperature);
        			g.drawLine(40, 450, 50 + counter, 450);//Horizontal line to be AUTO-GENERATED: Temperature
        			      
        			g.drawLine(40, 200, 60 + counter, 200);//Horizontal line to be AUTO-GENERATED: Voltage
        			      			
        			//Draw Voltage Graph bars
           	 		g.fillRect(rectX + counter, 200 - inputHeightVoltage, 10, rectY + inputHeightVoltage);
           	 		
           	 		// Voltage: x-axis labels
           	 		g.drawString(""+batteryCounter, rectX + counter, 230);           	 		
           	 		
           	 		//Temperature :x - axis labels
        			g.drawString(""+batteryCounter, 40 + counter, 470);
        			
        			//Temperature :y - axis
        			g.drawString("10", 20, 450 - 10);//10 label
        			g.drawString("20", 20, 450 - 20);//20 label
        			g.drawString("30", 20, 450 - 30);//30 label
        			g.drawString("40", 20, 450 - 40);//40 label
        			g.drawString("50", 20, 450 - 50);//50 label
           	 		 
           	 		//Voltage :y - axis label
           	 		g.drawString("10", 20, 200 - 10);//10 label
           	 		g.drawString("20", 20, 200 - 20);//20 label
           	 		g.drawString("30", 20, 200 - 30);//30 label
           	 		g.drawString("40", 20, 200 - 40);//10 label 
           	 		g.drawString("50", 20, 200 - 50);//10 label
           	 		
           	 		batteryCounter = batteryCounter + 1;
           	 		counter = counter + 18;
           	 		
           	 		
        		}while
        			(inputHeightTemperature != 0 || ! inputVoltage.equals(star) || !inputTemperature.equals(star));//Exit if Temperature value is empty and if '$' is read
        	     	
        	inFile.close(); 
        }	
        catch(FileNotFoundException e)
        	{
        		e.printStackTrace();
        	}
        
    }
    
    //Main Method
    public static void main (String []args)
    {
        OriginalJava xmain = new OriginalJava();
        xmain.addWindowFocusListener(new WindowAdapter()
                                     {
                                         public void windowClosing(WindowEvent e)
                                         {
                                             System.exit(0);
                                         }
                                     });
    }
}